apiready = function() {
  var NVNavigationBar = api.require('NVNavigationBar');
    seajs.use(["../../api", "../../jquery", "../../app","../../service"], function($api, $, app,service) {
        var vm = {
            el: '#app',
            data: {
                nav_list: ['推荐', '附近', '收藏'],
                inds: 0,
                offon:true,
                number:0,
                MessageNotReadCount:0
            },
            mounted: function() {
                this.init()
            },
            methods: {
                init: function() {
                    var that = this;
                    this.openNav()
                        // 打开页面
                    this.openFm_group()
                    if($api.getStorage('user')){
                    this.getMessageNotReadCount()
                    }
                },
                // 获取顶部的消息
                getMessageNotReadCount:function(){
                  var that = this;
                  app.ajax(
                      service['getMessageNotReadCount'], {
                          data: {
                              values: {
                                  mask: 'none'
                              }
                          }
                      },
                      function(res) {
                          if (res.code == 0) {
                            that.MessageNotReadCount = res.data
                          }
                      })
                },
                // 打开头部导航
                openNav: function() {
                  var that = this
                    NVNavigationBar.open({
                        rect: {
                            x: (api.frameWidth - 180) / 2,
                            y: 30,
                            w: 180,
                            h: 40
                        },
                        styles: {
                            orientation: 'horizontal',
                            bg: '#FFF',
                            bgAlpha: 1,
                            font: {
                                size: 18,
                                sizeSelected: 22,
                                color: '#000',
                                colorSelected: '#B188F5',
                                alpha: 1
                            },
                            itemSize: {
                                w: 60,
                                h: 44
                            }
                        },
                        items: [{
                            title: '推荐',
                            bg: '#fff'
                        }, {
                            title: '全部',
                            bg: '#fff'
                        }, {
                            title: '收藏',
                            bg: '#fff'
                        }],
                        selectedIndex: 0,
                        fixedOn: api.frameName,
                        id: 'nav'
                    }, function(ret, err) {
                      if(ret.eventType=='click'){
                          that.setPage(ret.index)
                      }
                    });
                },

                // // 设置头部页面
                // setNav: function(index) {
                //     this.inds = index
                //     this.setPage(index)
                //     $('.nav_bor').css('left', (index + 1) * 20 + 6 + 'vw')
                // },
                // 打开fm组页面
                openFm_group: function() {
                    var that = this
                    api.openFrameGroup({
                        name: 'home_group',
                        background: '#fff',
                        scrollEnabled: false,
                        preload: 2,
                        rect: {
                            x: 0,
                            y: 70,
                            w: api.winWidth,
                            h: api.winHeight - 120,
                            marginTop: 0,
                            marginBottom: 0
                        },
                        index: 0,
                        frames: [{
                            name: 'index_fm0',
                            url: './index_fm0.html',
                            bgColor: '#fff'
                        }, {
                            name: 'index_fm1',
                            url: './index_fm1.html',
                            bgColor: '#fff'
                        }, {
                            name: 'index_fm2',
                            url: './index_fm2.html',
                            bgColor: '#fff'
                        }]
                    }, function(ret, err) {
                        if (ret) {
                          that.setSelected(ret.index)
                          if(that.number==0){
                            that.number=1
                            api.setFrameGroupAttr({
                                name: 'home_group',
                                hidden: true
                            });
                          }
                        }
                    });

                },
                // 前往消息列表
                toMessage:function(){
                  api.openWin({
                      name: 'get_message',
                      url: './get_message.html'
                  });

                },
                // 设置导航选中
                setSelected:function(index){
                  NVNavigationBar.setSelected({
                      id: 'nav',
                      index: index,
                      selected: true
                  }, function(ret) {});
                },
                // 跳转页面
                setPage: function(index) {
                    api.setFrameGroupIndex({
                        name: 'home_group',
                        scroll: true,
                        index: index
                    });
                },
            }
        }
        var even = function() {
          // 监听去逛逛
          api.addEventListener({
              name: 'toIndex'
          }, function(ret, err){
            newVue.setSelected(0)
            newVue.setPage(0)
          });
          // 监听消息
          api.addEventListener({
              name: 'getMessageNotReadCount'
          }, function(ret, err){
              newVue.getMessageNotReadCount()
          });

          // 监听页面重新
          api.addEventListener({
              name: 'openFm_group'
          }, function(ret, err){
            newVue.openFm_group()
          });
        }
        var newVue = new Vue(vm);
        even();
        // V.apiready(vm,even);
    });

}
